package com.lucky.apple.test;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by he on 2018/5/9.
 */
public class test3 {
    public static void main(String[] args) {
        CloseableHttpClient client = HttpClients.createDefault();

        HttpGet httpGet = new HttpGet("http://113.215.26.194/files/71490000007FAB32/nginx.org/download/nginx-1.14.0.tar.gz");
        //httpGet.addHeader("Range","bytes=0-10000");
        try {
            CloseableHttpResponse response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();

            System.out.println(entity.getContentLength());
            InputStream stream = entity.getContent();
            // ZipInputStream zip = new ZipInputStream(stream);
            BufferedInputStream buff = new BufferedInputStream(stream);
            //RandomAccessFile file = new RandomAccessFile("D:\\work\\personal\\httpdown\\test2.txt", "rwd");
            //file.seek(0);
            int len = 0;
            int count = 0;
            StringBuilder stringBuilder = new StringBuilder();
            while ((len = buff.read()) != -1) {
                count++;
                // file.write(buff.read());
            }
            System.out.println(count);
            //file.close();
            buff.close();
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
